package exception;

import entity.Result;
import entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 自定义统一异常处理器
 * @ControllerAdvice  增强Controller
 */

@ControllerAdvice
public class BaseExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        return new Result(false, StatusCode.ERROR, e.getMessage());
    }

//    @ExceptionHandler(RuntimeException.class)
//    @ResponseBody
//    public Result RuntimeExceptionHandler(RuntimeException e) {
//        e.printStackTrace();
//        return new Result(false, StatusCode.ERROR, e.getMessage());
//    }
}
